﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.Web.Caching;
/// <summary>
/// get_roompart 的摘要说明
/// </summary>
public class get_roompart
{
    public static Cache _cache = HttpContext.Current.Cache;
    public get_roompart()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    #region 分区及区长信息
    public static string partintro(string partidx)
    {
      
        string constr = getsql.getstr("gamestr");
        DataTable metable = null;
        string infostr = "";

        try
        {
            metable = getpart();
            //	metable=SqlHelper.ExecuteDataTable(getsql.Get_constr("gamestr"), CommandType.StoredProcedure, "f_ktvpart_intro", p);
            DataRow[] merow = metable.Select("idx=" + partidx);
            if (merow.Length > 0)
            {
                string useridx = merow[0]["mayor"].ToString().Trim();
                string userid = merow[0]["id"].ToString().Trim();
                string username = merow[0]["myname"].ToString().Trim();
                string partname = merow[0]["partname"].ToString().Trim();
                string intro = merow[0]["introduce"].ToString().Trim();
                string qqnum = merow[0]["mastqq"].ToString().Trim();

                if (useridx == "0")
                {
                    useridx = "暂无";
                    userid = "暂无";
                }
                if (qqnum == "0")
                    qqnum = "";
                else
                    qqnum = "（QQ:" + merow[0]["mastqq"].ToString().Trim() + "）";
                infostr = "<div class='tips clearfix'><div class='qq'> 区长：" + useridx + qqnum + "</div><div class='text'>[" + partname + "] " + intro + "</div></div>";
                string name_p = merow[0]["mipname"].ToString().Trim();
                if (name_p == "")
                    name_p = partname;
                infostr = name_p + "&raquo;" + partname;
            }
        }
        catch
        {

        }
        return infostr;

    }
    #endregion
    #region 得到分区
    public static DataTable getpart()
    {
        DataTable metable = null;
        SqlParameter[] p ={ };
        if (_cache["partinfo"] == null)
        {
            metable = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "f_ktvpart_intro", p);
            _cache.Insert("partinfo", metable, null, DateTime.Now.AddMinutes(3), TimeSpan.Zero);
        }
        else
        {
            metable = (DataTable)_cache["partinfo"];
        }
        return metable;
    }
    #endregion
    #region 得到网监用超管
    public static DataTable getadmin()
    {
        DataTable metable = null;
        try
        {
            if (_cache["Adminlist"] != null)
            {
                metable = _cache["Adminlist"] as DataTable;
            }
            else
            {
                string ConnStr = getsql.getstr("gamestr");
                SqlParameter[] p ={ };
                metable = SqlHelper.ExecuteDataTable(ConnStr, CommandType.StoredProcedure, "f_get_adminlist", p);
                _cache.Insert("Adminlist", metable, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
        }
        catch { }
        return metable;
    }

    public static DataTable getadmin_p()
    {
        DataTable metable = null;
        try
        {
            if (_cache["partadmin"] != null)
            {
                metable = _cache["partadmin"] as DataTable;
            }
            else
            {
                string ConnStr = getsql.getstr("gamestr");
                SqlParameter[] p ={ };
                metable = SqlHelper.ExecuteDataTable(ConnStr, CommandType.StoredProcedure, "f_get_adminlist_p", p);
                _cache.Insert("partadmin", metable, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
        }
        catch { }
        return metable;
    }
    public static DataTable getpolice()
    {
        DataTable metable = null;
        try
        {
            if (_cache["police_admin"] != null)
            {
                metable = _cache["police_admin"] as DataTable;
            }
            else
            {
                string ConnStr = getsql.getstr("gamestr");
                SqlParameter[] p ={ };
                metable = SqlHelper.ExecuteDataTable(ConnStr, CommandType.StoredProcedure, "f_get_multipolice", p);
                _cache.Insert("police_admin", metable, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
            }
        }
        catch { }
        return metable;
    }
    public static DataTable getroom_ten()
    {
        DataTable metable = null;
        try
        {
            if (_cache["TenRoom"] != null)
            {
                metable = _cache["TenRoom"] as DataTable;
            }
            else
            {
                string ConnStr = getsql.getstr("gamestr1");
                SqlParameter[] p ={ };
                metable = SqlHelper.ExecuteDataTable(ConnStr, CommandType.StoredProcedure, "f_select_ten_roomlist_test3", p);
                _cache.Insert("TenRoom", metable, null, DateTime.Now.AddMinutes(3), TimeSpan.Zero);
            }
        }
        catch { }
        return metable;
    }

    public static DataTable getroom()
    {
        DataTable metable = null;
        try
        {
            if (_cache["roomlist_t"] == null)
            {
                SqlParameter[] p =
                 {
                    
                 };

                metable = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "[dbo].[f_multiroom_list_test]", p);
                _cache.Insert("roomlist_t", metable, null, DateTime.Now.AddMinutes(3), TimeSpan.Zero);
            }
            else
            {
                metable = (DataTable)_cache["roomlist_t"];
            }
        }
        catch { }
        return metable;
    }

    public static DataTable getroom_web()
    {
        DataTable metable = null;
        try
        {
            if (_cache["roomweb"] == null)
            {
                SqlParameter[] p =
                 {
                    
                 };

                metable = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "[dbo].[f_multiroom_list_web]", p);//测试f_multiroom_list_web_test    //正式 f_multiroom_list_web
                _cache.Insert("roomweb", metable, null, DateTime.Now.AddMinutes(3), TimeSpan.Zero);
            }
            else
            {
                metable = (DataTable)_cache["roomweb"];
            }
        }
        catch { }
        return metable;
    }

    public static DataRow[] getroom_serverid(int serverid,int sortype,int vtype)
    {
        DataTable metable = getroom_web();
        DataRow[] merow = null;
        try
        {
            if (_cache["roomweb_" + serverid+"_"+sortype+"_"+vtype] == null)
            {
                if (metable != null)
                {
                    if(sortype==1)
                    {
                        if(vtype==1)
                        {
                             merow = metable.Select("servertypeidx=" + serverid + " and onlineusernum>0","starnum desc");
                        }
                        else
                        {
                            merow = metable.Select("servertypeidx=" + serverid + " and onlineusernum>0","onlineusernum desc");
                        }
                    }
                    else
                    {
                        if(vtype==1)
                        {
                             merow = metable.Select("servertypeidx=" + serverid + " and onlineusernum=0","starnum desc");
                        }
                        else
                        {
                            merow = metable.Select("servertypeidx=" + serverid + " and onlineusernum=0");
                        }
                 
                   /* switch (sortype)
                    { 
                        case 1:
                            merow = metable.Select("servertypeidx=" + serverid + " and onlineusernum>0");
                            break;
                        case 2:
                           // merow = metable.Select("servertypeidx=" + serverid + " and starnum>0");
                             merow = metable.Select("servertypeidx=" + serverid + " and onlineusernum=0");
                            break;
                        case 3:
                            merow = metable.Select("servertypeidx=" + serverid ,"onlineusernum desc");
                            break;
                        case 4:
                            merow = metable.Select("servertypeidx=" + serverid, "starnum desc");
                            break;
                        default:
                            merow = metable.Select("servertypeidx=" + serverid + " and onlineusernum=0");
                            break;*/
                    }

                    if (merow != null)
                    {
                        _cache.Insert("roomweb_" + serverid+"_"+sortype+"_"+vtype, merow, null, DateTime.Now.AddMinutes(3), TimeSpan.Zero);
                    }
                }
            }
            else
            {
                merow = (DataRow[])_cache["roomweb_" + serverid+"_"+sortype+"_"+vtype];
            }
        }
        catch
        { }
        return merow;
    }
    public static int tuiroom_check(string roomid)
    {
        string ConnStr = getsql.getstr("gamestr");
        int ret = 0;
        try
        {
            if (_cache["tuiroom"] == null)
            {
                SqlParameter[] p ={ };
                DataTable dt = SqlHelper.ExecuteDataTable(ConnStr, CommandType.StoredProcedure, "f_get_tuiroom_all", p);
                _cache.Insert("tuiroom", dt, null, DateTime.Now.AddMinutes(3), TimeSpan.Zero);
            }
            DataTable tuitable = (DataTable)_cache["tuiroom"];
            ret = tuitable.Select("roomid=" + roomid).Length;
        }
        catch
        {
        }
        return ret;
    }

    public static DataTable getuser(string userid)
    {
        DataTable dt = null;
        try
        {
            SqlParameter[] p =
			{
				SqlHelper.MakeInParam("@Id", SqlDbType.VarChar, 20, userid)
			};
            dt = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "Umanager_Select_MemberInforById", p);
        }
        catch { }
        return dt;
    }

    public static DataTable getgift()
    {
        DataTable metable = null;
        try
        {
            if (_cache["Propeccount"] == null)
            {
                SqlParameter[] p ={ };
                metable = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "f_day_perlist_change", p);
                _cache.Insert("Propeccount", metable, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
            else
            {
                metable = (DataTable)_cache["Propeccount"];
            }
        }
        catch { }

        return metable;
    }

    public static DataTable getrand_all()
    {

        DataTable metable = null;
        try
        {
            SqlParameter[] p ={
								 
							 };
            if (_cache["hall_rand"] == null)
            {
                metable = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "f_rand_all", p);
                _cache.Insert("hall_rand", metable, null, DateTime.Now.AddMinutes(8), TimeSpan.Zero);
            }
            else
            {
                metable = (DataTable)_cache["hall_rand"];
            }
        }
        catch { }
        return metable;


    }
    #endregion

    #region 用户登陆验证
    public static DataRow checklog(string UserId, string Pwd)
    {
        DataTable dt = new DataTable();
        SqlParameter[] p =
			{
				SqlHelper.MakeInParam("@UserId",SqlDbType.VarChar,20,UserId),
				SqlHelper.MakeInParam("@Pwd",SqlDbType.VarChar,32,Pwd)	
			};
        try
        {
            dt = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "Index_Member_Login", p);
            //			dt = SqlHelper.ExecuteDataTable(ConfigurationSettings.AppSettings["gamestr"],CommandType.StoredProcedure,"Index_Member_Login", p);
        }
        catch
        {
            throw;//return null;
        }
        if (dt.Rows.Count > 0)
        {
            return dt.Rows[0];
        }
        else
        {
            return null;
        }
    }
    #endregion
    #region
   

    
      #endregion

#region 点歌之星 hotmember
    public static DataTable gethotmember()
    {
        SqlParameter[] p ={ };
        DataTable metable = null;
        if (_cache["hotmember"] == null || ((DataTable)_cache["hotmember"]).Rows.Count==0)
        {
            metable = SqlHelper.ExecuteDataTable(getsql.getstr("gamestr"), CommandType.StoredProcedure, "f_songstar_getall_web", p);//f_songstar_getall
            _cache.Insert("hotmember", metable, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
        }
        else
        {
            metable = (DataTable)_cache["hotmember"];
        }
        return metable;
    }
#endregion

    #region 得到公告信息
    public static DataSet getaffiche()
    {
        DataSet ds = null;
        if (_cache["affiche"] == null)
        {
            SqlParameter[] p ={ };
            ds = SqlHelper.ExecuteDataset(getsql.getstr("gamestr"), CommandType.StoredProcedure, "f_ten_affichelist", p);
            _cache.Insert("affiche", ds, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
        }
        else
        {
            ds = (DataSet)_cache["affiche"];
        }
        return ds;
    }
    #endregion

    #region 明星有约
    public static DataTable get_starmeet()
    {
        DataTable metable = null;
        try
        {
            SqlParameter[] p ={
								 
							 };
            if (_cache["star_meet"] == null)
            {
                metable = SqlHelper.ExecuteDataTable(getsql.getstr("sql59"), CommandType.StoredProcedure, "V6cn_select_starabout", p);
                _cache.Insert("star_meet", metable, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
            else
            {
                metable = (DataTable)_cache["star_meet"];
            }
        }
        catch { }
        return metable;
    }

    public static string roomin_mul(int roomidx)
    {
        return roomidx.ToString();
    }
    #endregion
}
